package com.sy.musicapp.ui.common

import androidx.compose.foundation.clickable
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.ui.Modifier
import androidx.compose.ui.layout.layout
import androidx.navigation.NavController
import com.sy.musicapp.model.Screen
import kotlin.math.min


fun Modifier.keepSquare() = layout { measurable, constraints ->
    val placeable = measurable.measure(constraints)
    val size = min(placeable.width, placeable.height)
    layout(size, size) {
        placeable.place(0, 0)
    }
}



fun Modifier.noRippleClickable(onClick: () -> Unit): Modifier = this.then(
    clickable(interactionSource = MutableInteractionSource(), indication = null, onClick = onClick)
)

fun Modifier.fillMaxSize(width: Float, height: Float): Modifier = this.then(
    fillMaxWidth(width).fillMaxHeight(height)
)


fun NavController.navigate(screen: Screen) {
    navigate(screen.route, navOptions = null)
}